package Leetcode.LeetcodeDemo1;

import java.util.ArrayList;
import java.util.List;
public class LeetCode47 {
    public static List<List<Integer>> permuteUnique(int[] nums) {
        List<List<Integer>> list=new ArrayList<List<Integer>>();
        progress(nums,0,list);
        return list;
    }
    public static void progress(int[] nums,int i,List<List<Integer>> list){
        if(i==nums.length){
            List<Integer> newlist=new ArrayList<Integer>();
            for(int k=0;k<nums.length;k++){
                newlist.add(nums[k]);
            }
            list.add(newlist);
        }
        boolean[] visit=new boolean[21];
        for(int j=i;j<nums.length;j++){
            if(!visit[nums[j]+10]){
                visit[nums[j]+10]=true;
                swap(nums,i,j);
                progress(nums,i+1,list);
                swap(nums,i,j);
            }

        }
    }
    public static void swap(int[] arr,int i,int j){
        int tmp=arr[i];
        arr[i]=arr[j];
        arr[j]=tmp;
    }

    public static void main(String[] args) {
        int[] arr={1,2,3};
        List<List<Integer>> lists = permuteUnique(arr);
        for (List<Integer> list : lists) {
            for (Integer i : list) {
                System.out.print(i);
            }
            System.out.println();
        }
    }

}
